//
//  SFLoginGetAccountView.swift
//  SwiftForwardWayXu
//
//  Created by 郑程旭 on 2022/1/10.
//

import UIKit

class SFLoginGetAccountView: SFBaseView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.isHidden = true
        self.alpha = 0
        self.backgroundColor = .lightGray.withAlphaComponent(0.5)
        
        self.configSubviews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: - 创建子视图
    private func configSubviews() -> Void {
        self.addSubview(self.promptView)
        promptView.snp.makeConstraints { make in
            make.width.equalTo(280)
            make.height.equalTo(355)
            make.center.equalTo(self).offset(0)
        }
    }
    
    lazy var promptView: UIView = {
        let promptView = UIView.init()
        promptView.backgroundColor = .white
        promptView.layer.cornerRadius = 10
        promptView.layer.masksToBounds = true
        
        let knowBtn = UIButton.init(type: UIButton.ButtonType.custom)
        knowBtn.setTitle("我知道了", for: UIControl.State.normal)
        knowBtn.setTitleColor(kTintColor, for: UIControl.State.normal)
        knowBtn.titleLabel?.font = .systemFont(ofSize: 18)
        knowBtn.addTarget(self, action: #selector(hiddenGetAccountView), for: UIControl.Event.touchUpInside)
        promptView.addSubview(knowBtn)
        knowBtn.snp.makeConstraints { make in
            make.left.bottom.right.equalTo(0)
            make.height.equalTo(60)
        }
        
        let lineView = UIView.init()
        lineView.backgroundColor = kHexColor(hex: 0xF2F2F2, alpha: 1)
        promptView.addSubview(lineView)
        lineView.snp.makeConstraints { make in
            make.left.equalTo(16)
            make.right.equalTo(-16)
            make.bottom.equalTo(knowBtn.snp.top)
            make.height.equalTo(1)
        }
        
        let closeBtn = UIButton.init(type: UIButton.ButtonType.custom)
        closeBtn.setImage(UIImage.init(named: "eyeTestClose"), for: UIControl.State.normal)
        closeBtn.addTarget(self, action: #selector(hiddenGetAccountView), for: UIControl.Event.touchUpInside)
        promptView.addSubview(closeBtn)
        closeBtn.snp.makeConstraints { make in
            make.width.height.equalTo(35)
            make.top.equalTo(10)
            make.right.equalTo(-10)
        }
  
        let iconImgv = UIImageView.init()
        iconImgv.image = UIImage.init(named: "alert_pop_icon_loudSpeaker")
        promptView.addSubview(iconImgv)
        iconImgv.snp.makeConstraints { make in
            make.top.equalTo(16)
            make.width.height.equalTo(80)
            make.centerX.equalTo(promptView).offset(0)
        }
        
        let titleLbl = UILabel.init()
        titleLbl.text = "如何获得登录账号"
        titleLbl.font = .systemFont(ofSize: 18)
        promptView.addSubview(titleLbl)
        titleLbl.snp.makeConstraints { make in
            make.centerX.equalTo(promptView).offset(0)
            make.top.equalTo(iconImgv.snp.bottom).offset(15)
        }
        
        let contentLbl = UILabel.init()
        contentLbl.text =  "视力筛查登录账号由负责学校筛查的“筛查单位后台”进行账号分配，请联系您的筛查单位帮您分配登录账号。\n\n注：广西壮族自治区学生普查，请选择广西，其他地区或单位请选择全国。"
        contentLbl.font = .systemFont(ofSize: 15)
        contentLbl.numberOfLines = 0
        promptView.addSubview(contentLbl)
        contentLbl.snp.makeConstraints { make in
            make.left.right.equalTo(lineView)
            make.top.equalTo(titleLbl.snp.bottom).offset(20)
        }

        return promptView
    }()
        
    
    //MARK: - 显示/隐藏
    public func showGetAccountView(superView: SFLoginView) -> Void {
        superView.addSubview(self)
        self.snp.makeConstraints { make in
            make.edges.equalTo(0)
        }
        self.isHidden = false
        UIView.animate(withDuration: 0.3) {
            self.alpha = 1
        }
    }
    
    @objc private func hiddenGetAccountView() -> Void {
        UIView.animate(withDuration: 0.3) {
            self.alpha = 0
        } completion: { _ in
            self.isHidden = true
            self.removeFromSuperview()
        }
    }
    
}
